package com.kordar.api.modular.unicomJS;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.DigestUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

public enum SysParams {

    SYS_APP_CODE("appCode", "1frakKi6dWEJJKNzeNVxg9wMFd1X175ZQtAuCxn8l0a6KQeOAZGJx39m8ewB"),
    SYS_SECRET_KEY("secretKey", "2fjFiRixHY7BOOCLgUe9qwiga7MUucTy"),
    SYS_SIGN("sign", "MD5签名"),
    SYS_TIME_STAMP("timestamp", "时间戳"),
    SYS_UUID("uuid", "UUID");

    private static final Logger logger = LoggerFactory.getLogger(SysParams.class);

    private String code;
    private String name;

    SysParams(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static String getTimestamp() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(new Date());
    }

    public static String getUUID() {
        return UUID.randomUUID().toString();
    }

    public static String getSign(String timestamp, String uuid) {

        String sb = "appCode" + SysParams.SYS_APP_CODE.getName() +
                "timestamp" + timestamp +
                "uuid" + uuid +
                SysParams.SYS_SECRET_KEY.getName();
        String waitSignString = sb.replaceAll(" ", "");
        logger.debug("生成字符串:{}", waitSignString);
        return DigestUtils.md5DigestAsHex(waitSignString.getBytes());
    }
}
